package com.java1412.service.impl;

import com.java1412.service.MessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author java1412
 * @create 2021-06-07 10:09
 */
@EnableBinding(Source.class) // 定义消息的推送管道（Source是spring的）
public class MessageProviderImpl implements MessageProvider {

    @Resource
    private MessageChannel output;  // 消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        // MessageBuilder是spring的integration.support.MessageBuilder
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("*********serial : " + serial);
        return serial;
    }
}
